﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Actuals.CoreDomain;
using Actuals.CoreDomain.Data;

namespace Actuals.Data
{
    public class DalPartTimeDetails : Dal<IPartTimeDetails, PartTimeDetails>, IDalPartTimeDetails
    {
         private readonly IDalManager _manager;
        private static readonly IDalPartTimeDetails _instance = new DalPartTimeDetails();
        private const string SP_GET_PART_TIME_DETAILS = "usp_GetPartTimeDetails";
        private const string SP_ADD_PART_TIME_DETAILS = "usp_AddPartTimeDetails";
        private const string SP_GET_PART_TIME_DETAILS_FOR_TEAM  = "usp_GetPartTimeDetailsForTeam";
        private const string SP_DELETE_PART_TIME_DETAILS = "usp_DeletePartTimeDetails";

        

        public static IDalPartTimeDetails Instance
        {
            get { return _instance; }
        }

        public DalPartTimeDetails()
        {
            _manager = new DalManager();
        }

        public DalPartTimeDetails(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(IPartTimeDetails obj, DataRow row)
        {
            obj.EmployeeId = _manager.GetValue<int>(row, "EmployeeId");
            obj.PartTimeId= _manager.GetValue<Int64>(row, "PartTimeId");
          
            obj.TeamId = _manager.GetValue<int>(row, "TeamId");
            obj.WorkDate = _manager.GetValue<DateTime>(row, "WorkDate");
            obj.NoOfHours = _manager.GetValue<int>(row, "NoOfHours");
        }

      
        public IList<IPartTimeDetails> GetPartTimeDetails(int employeeId)
        {
            _manager.StoredProcedureName = SP_GET_PART_TIME_DETAILS;
            _manager.AddInParameter("@EmployeeId", DbType.Int32, employeeId);
            
                    
           
             IList<IPartTimeDetails> partTimeDetails = new List<IPartTimeDetails>();
             foreach (IPartTimeDetails partTimeDetail in ConvertAll(_manager.ExecuteDataSet()))
                 partTimeDetails.Add(partTimeDetail);

             return partTimeDetails;

               
        }
       public  bool AddPartTimeDetails(IPartTimeDetails partTimeDetails)
        {
            _manager.StoredProcedureName = SP_ADD_PART_TIME_DETAILS;
            _manager.AddInParameter("@EmployeeId", DbType.Int32, partTimeDetails.EmployeeId);
            _manager.AddInParameter("@TeamId", DbType.Int32, partTimeDetails.TeamId);
            _manager.AddInParameter("@WorkDate", DbType.DateTime, partTimeDetails.WorkDate);
            _manager.AddInParameter("@NoOfHours", DbType.Int32, partTimeDetails.NoOfHours);
            _manager.ExecuteNonQuery();
            return true;
        }


        public IList<IPartTimeDetails> GetPartTimeDetailsForTeam(int teamId)
        {
            _manager.StoredProcedureName = SP_GET_PART_TIME_DETAILS_FOR_TEAM;
            _manager.AddInParameter("@TeamId", DbType.Int32, teamId);



            IList<IPartTimeDetails> partTimeDetails = new List<IPartTimeDetails>();
            foreach (IPartTimeDetails partTimeDetail in ConvertAll(_manager.ExecuteDataSet()))
                partTimeDetails.Add(partTimeDetail);

            return partTimeDetails;


        }
       public bool DeletePartTimeDetails(int partTimeId)
        {
            _manager.StoredProcedureName = SP_DELETE_PART_TIME_DETAILS;
            _manager.AddInParameter("@PartTimeId", DbType.Int32, partTimeId);
            _manager.ExecuteNonQuery();
            return true;
        }


    }
}
